package com.lxg.controller;

import com.lxg.shibie.UploadService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.MultipartHttpServletRequest;

import java.io.IOException;

// controller层代码
@Controller
public class UploadController {

    @Autowired
    private UploadService uploadService;

    @GetMapping("/getphoto")
    public String photo(){
        return "photo";
    }


    @PostMapping("/image2")
    public ResponseEntity<String> uploadImage(MultipartHttpServletRequest request) throws IOException {
        MultipartFile file = request.getFile("file");
        String resultUrl;
        byte[] bytes = file.getBytes();
        resultUrl = uploadService.uploadImage( bytes, ".png");
        return ResponseEntity.ok(resultUrl);
    }
}

